AlarmQuery Methods
The AlarmQuery object contains the following methods:
Note: Some of the examples in this topic use the WScript.Sleep statement, which is not available for use when scripting in CygNet Studio or in the HSS. Use TheView's EventTimer instead.
CancelAlarmFiltering
The CancelAlarmFiltering method cancels the filtering of alarms.
Syntax
CancelAlarmFiltering()
Example
The following example cleans up the query after it is finished, by canceling the filtering destroying the filter.
Sub
' alarm query is finished
AlarmQuery.CancelAlarmFiltering()
AlarmQuery.DestroyAlarmFilter(100)
End Sub
ClearQueryResults
The ClearQueryResults method clears the results of a previous query and initializes the processing flags. The query (filter) itself is not cleared.
Syntax
ClearQueryResults()
Remark
Clearing the results of a previous query is good programming practice if multiple queries are to be performed.
Example
The following example addresses clearing the query results before retrieving data from the query.
Sub
' query is all set up
While bIsFiltering
WScript.Sleep(1000)
' call before retrieving data
AlarmQuery.ClearQueryResults()
' retrieve data, etc.
Wend
End Sub
CreateAlarmFilter
The CreateAlarmFilter method creates a new alarm filter thread.
Syntax
CreateAlarmFilter(StartTime As Date, EndTime As Date, UpdateInterval As Integer) As Boolean
Parameters
| Parameter | Required | Description |
|---|---|---|
|
StartTime |
Yes |
The earliest date/time of alarms to be filtered. Note that this value can either be a string in the machine-chosen date/time format (i.e. "MM/DD/YY hh:mm:ss" for a machine using the American date/time format), or it can be a Date returned from the CDate function. |
|
EndTime |
Yes |
The latest date/time of alarms to be filtered. Note that this value can either be a string in the machine-chosen date/time format (i.e. "MM/DD/YY hh:mm:ss" for a machine using the American date/time format), or it can be a Date returned from the CDate function. |
|
UpdateInterval |
Yes |
The periodic run interval in seconds. If this value is zero, the query will only run once. |
Remark
The StartTime and EndTime parameters will be ignored if the "ReportTime" property is used in the filter passed into SetAlarmFilterAsXml and the FilterContainsDates parameter of that method is set to "true" (see SetAlarmFilterAsXml).
The StartTime and EndTime parameters do not get included into the filter until SetAlarmFilterAsXml is called. If no additional filtering (besides start/end times and site services) is desired, call SetAlarmFilterAsXml with a blank filter string and FilterContainsDates parameter set to false after calling CreateAlarmFilter and SetAlarmSiteServices.
Example
The following example goes through the entire process of creating a filter, setting the XML filter, setting the notification point, starting the query, retrieving data, displaying the results, and cleaning up the query.
Sub
'-----------------SETUP------------------
Dim date1, date2
date1 = Date - 10
date2 = Date
Dim startDate, endDate
startDate = CDate(date1)
endDate = CDate(date2)
'create alarm filter for alarms between now and 10 days ago
Dim bCreatedOk
bCreatedOk = AlarmQuery.CreateAlarmFilter(startDate, endDate, 5)
'initialize the filter (this step is good practice)
AlarmQuery.ClearQueryResults
'set the service-specific filter from an existing XML (see the documentation for
'SetAlarmFilterAsXml for an example of an XML filter)
Dim bSetFilter
bSetFilter = AlarmQuery.SetAlarmFilterAsXml(g_xmlFilter, false)
AlarmQuery.SetAlarmSiteServices("CYGDEMO.CAS")
'set notification point
AlarmQuery.SetNotificationPoint "CYGDEMO.UIS:EVENTIF_NOTIFICATION_PT"
'-----------------EXECUTION------------------
AlarmQuery.StartAlarmFiltering()
'check to see if filter has been set up correctly
Dim bIsFiltering, bIsRunning
bIsFiltering = AlarmQuery.IsAlarmFilterFiltering()
bIsRunning = AlarmQuery.IsAlarmFilterRunning()
WScript.Sleep(1000)
Dim pvTagList, bAlarmsRetrieved
pvTagList = ""
bAlarmsRetrieved = AlarmQuery.GetFilteredAlarmList(pvTagList)
Dim nSize, bSizeRetrieved
nSize = 0
bSizeRetrieved = AlarmQuery.GetFilteredAlarmListSize(nSize)
If nSize > 0 Then
Dim strTag, pvAlarmInfoXml, bAlarmRetrieved, iRec
For iRec = 0 To UBound(pvTagList)
strTag = pvTagList(iRec)
pvAlarmInfoXml = ""
bAlarmRetrieved = AlarmQuery.GetAlarmInfoAsXml(strTag, pvAlarmInfoXml)
MsgBox pvAlarmInfoXml
Next
'clear the query and the cache
AlarmQuery.ClearQueryResults
End If
'alarm query is finished
AlarmQuery.CancelAlarmFiltering()
AlarmQuery.DestroyAlarmFilter(100)
End Sub
DestroyAlarmFilter
The DestroyAlarmFilter method terminates execution of the filter thread, and waits for the specified number of seconds.
Syntax
DestroyAlarmFilter(TimeToWaitInSeconds As Integer) As Boolean
Parameters
| Parameter | Required | Description |
|---|---|---|
|
TimeToWaitInSeconds |
Yes |
The number of seconds to wait for the alarm query to terminate. This value must be within the range [1 - 100]. |
Remark
This method will hang for the specified number of seconds while the filter thread terminates. If the filter thread has not terminated by the time the interval has expired, this method will return false and the filter thread will continue to attempt to terminate in the background. Call this method as part of the cleanup routine after querying is finished.
Example
The following example cleans up the query after it is finished, by canceling the filtering and destroying the filter.
Sub
' alarm query is finished
AlarmQuery.CancelAlarmFiltering()
AlarmQuery.DestroyAlarmFilter(100)
End Sub
GetAlarmFilterAsXml
The GetAlarmFilterAsXml method returns the alarm filter as an XML string.
Syntax
GetAlarmFilterAsXml(XmlFilter As Variant) As Boolean
Parameters
| Parameter | Required | Description |
|---|---|---|
|
XmlFilter |
Yes |
The XML string returned from this method. |
Example
The following example sets the alarm filter, then retrieves it from the query and displays it.
Sub
' set the alarm filter from an existing XML (see the documentation for
'SetAlarmFilterAsXml for an example of an XML filter)
Dim bSetFilter
bSetFilter = AlarmQuery.SetAlarmFilterAsXml(g_xmlAlarmFilter)
Dim xmlAlarmFilter
If (bSetFilter) Then
bGetFilter = AlarmQuery.GetAlarmFilterAsXml(xmlAlarmFilter)
If (bGetFilter) Then
MsgBox xmlAlarmFilter
End If
End If
End Sub
GetAlarmInfoAsXml
The GetAlarmInfoAsXml method returns alarm information for the given tag.
Syntax
GetAlarmInfoAsXml(Tag As String, AlarmInfoXml As Variant) As Boolean
Parameters
| Parameter | Required | Description |
|---|---|---|
|
Tag |
Yes |
A fully qualified point tag. |
|
AlarmInfoXml |
Yes |
The alarm information for the tag returned as an XML string. |
Remark
After querying is complete, this method is used in conjunction with GetFilteredAlarmList to display the results of the query.
Example
The following example goes through the entire process of creating a filter, setting the XML filter, setting the notification point, starting the query, retrieving data, displaying the results, and cleaning up the query.
Sub
'-----------------SETUP------------------
Dim date1, date2
date1 = Date - 10
date2 = Date
Dim startDate, endDate
startDate = CDate(date1)
endDate = CDate(date2)
'create alarm filter for alarms between now and 10 days ago
Dim bCreatedOk
bCreatedOk = AlarmQuery.CreateAlarmFilter(startDate, endDate, 5)
'initialize the filter (this step is good practice)
AlarmQuery.ClearQueryResults
'set the service-specific filter from an existing XML (see the documentation for
'SetAlarmFilterAsXml for an example of an XML filter)
Dim bSetFilter
bSetFilter = AlarmQuery.SetAlarmFilterAsXml(g_xmlFilter, false)
AlarmQuery.SetAlarmSiteServices("CYGDEMO.CAS")
'set notification point
AlarmQuery.SetNotificationPoint "CYGDEMO.UIS:EVENTIF_NOTIFICATION_PT"
'-----------------EXECUTION------------------
AlarmQuery.StartAlarmFiltering()
'check to see if filter has been set up correctly
Dim bIsFiltering, bIsRunning
bIsFiltering = AlarmQuery.IsAlarmFilterFiltering()
bIsRunning = AlarmQuery.IsAlarmFilterRunning()
WScript.Sleep(1000)
Dim pvTagList, bAlarmsRetrieved
pvTagList = ""
bAlarmsRetrieved = AlarmQuery.GetFilteredAlarmList(pvTagList)
Dim nSize, bSizeRetrieved
nSize = 0
bSizeRetrieved = AlarmQuery.GetFilteredAlarmListSize(nSize)
If nSize > 0 Then
Dim strTag, pvAlarmInfoXml, bAlarmRetrieved, iRec
For iRec = 0 To UBound(pvTagList)
strTag = pvTagList(iRec)
pvAlarmInfoXml = ""
bAlarmRetrieved = AlarmQuery.GetAlarmInfoAsXml(strTag, pvAlarmInfoXml)
MsgBox pvAlarmInfoXml
Next
'clear the query and the cache
AlarmQuery.ClearQueryResults
End If
'alarm query is finished
AlarmQuery.CancelAlarmFiltering()
AlarmQuery.DestroyAlarmFilter(100)
End Sub
GetFilteredAlarmList
The GetFilteredAlarmList method returns the list of filtered alarms as fully qualified point tags.
Syntax
GetFilteredAlarmList(SiteSvcKeyList As Array) As Boolean
Parameters
| Parameter | Required | Description |
|---|---|---|
|
SiteSvcKeyList |
Yes |
A list of fully qualified point tags representing the filtered alarms. |
Remark
After querying is complete, this method is used in conjunction with GetAlarmInfoAsXml to display the results of the query.
Example
The following example goes through the entire process of creating a filter, setting the XML filter, setting the notification point, starting the query, retrieving data, displaying the results, and cleaning up the query.
Sub
'-----------------SETUP------------------
Dim date1, date2
date1 = Date - 10
date2 = Date
Dim startDate, endDate
startDate = CDate(date1)
endDate = CDate(date2)
'create alarm filter for alarms between now and 10 days ago
Dim bCreatedOk
bCreatedOk = AlarmQuery.CreateAlarmFilter(startDate, endDate, 5)
'initialize the filter (this step is good practice)
AlarmQuery.ClearQueryResults
'set the service-specific filter from an existing XML (see the documentation for
'SetAlarmFilterAsXml for an example of an XML filter)
Dim bSetFilter
bSetFilter = AlarmQuery.SetAlarmFilterAsXml(g_xmlFilter, false)
AlarmQuery.SetAlarmSiteServices("CYGDEMO.CAS")
'set notification point
AlarmQuery.SetNotificationPoint "CYGDEMO.UIS:EVENTIF_NOTIFICATION_PT"
'-----------------EXECUTION------------------
AlarmQuery.StartAlarmFiltering()
'check to see if filter has been set up correctly
Dim bIsFiltering, bIsRunning
bIsFiltering = AlarmQuery.IsAlarmFilterFiltering()
bIsRunning = AlarmQuery.IsAlarmFilterRunning()
WScript.Sleep(1000)
Dim pvTagList, bAlarmsRetrieved
pvTagList = ""
bAlarmsRetrieved = AlarmQuery.GetFilteredAlarmList(pvTagList)
Dim nSize, bSizeRetrieved
nSize = 0
bSizeRetrieved = AlarmQuery.GetFilteredAlarmListSize(nSize)
If nSize > 0 Then
Dim strTag, pvAlarmInfoXml, bAlarmRetrieved, iRec
For iRec = 0 To UBound(pvTagList)
strTag = pvTagList(iRec)
pvAlarmInfoXml = ""
bAlarmRetrieved = AlarmQuery.GetAlarmInfoAsXml(strTag, pvAlarmInfoXml)
MsgBox pvAlarmInfoXml
Next
'clear the query and the cache
AlarmQuery.ClearQueryResults
End If
'alarm query is finished
AlarmQuery.CancelAlarmFiltering()
AlarmQuery.DestroyAlarmFilter(100)
End Sub
GetFilteredAlarmListSize
The GetFilteredAlarmListSize method returns the size of the filtered alarm list as an integer
Syntax
GetFilteredAlarmListSize(Size As Integer) As Boolean
Parameters
| Parameter | Required | Description |
|---|---|---|
|
Size |
Yes |
The size of the filtered alarm list. |
Remark
The filtered alarm list itself can be obtained via GetFilteredAlarmList.
Example
The following example goes through the entire process of creating a filter, setting the XML filter, setting the notification point, starting the query, retrieving data, displaying the results, and cleaning up the query.
Sub
'-----------------SETUP------------------
Dim date1, date2
date1 = Date - 10
date2 = Date
Dim startDate, endDate
startDate = CDate(date1)
endDate = CDate(date2)
'create alarm filter for alarms between now and 10 days ago
Dim bCreatedOk
bCreatedOk = AlarmQuery.CreateAlarmFilter(startDate, endDate, 5)
'initialize the filter (this step is good practice)
AlarmQuery.ClearQueryResults
'set the service-specific filter from an existing XML (see the documentation for
'SetAlarmFilterAsXml for an example of an XML filter)
Dim bSetFilter
bSetFilter = AlarmQuery.SetAlarmFilterAsXml(g_xmlFilter, false)
AlarmQuery.SetAlarmSiteServices("CYGDEMO.CAS")
'set notification point
AlarmQuery.SetNotificationPoint "CYGDEMO.UIS:EVENTIF_NOTIFICATION_PT"
'-----------------EXECUTION------------------
AlarmQuery.StartAlarmFiltering()
'check to see if filter has been set up correctly
Dim bIsFiltering, bIsRunning
bIsFiltering = AlarmQuery.IsAlarmFilterFiltering()
bIsRunning = AlarmQuery.IsAlarmFilterRunning()
WScript.Sleep(1000)
Dim pvTagList, bAlarmsRetrieved
pvTagList = ""
bAlarmsRetrieved = AlarmQuery.GetFilteredAlarmList(pvTagList)
Dim nSize, bSizeRetrieved
nSize = 0
bSizeRetrieved = AlarmQuery.GetFilteredAlarmListSize(nSize)
If nSize > 0 Then
Dim strTag, pvAlarmInfoXml, bAlarmRetrieved, iRec
For iRec = 0 To UBound(pvTagList)
strTag = pvTagList(iRec)
pvAlarmInfoXml = ""
bAlarmRetrieved = AlarmQuery.GetAlarmInfoAsXml(strTag, pvAlarmInfoXml)
MsgBox pvAlarmInfoXml
Next
'clear the query and the cache
AlarmQuery.ClearQueryResults
End If
'alarm query is finished
AlarmQuery.CancelAlarmFiltering()
AlarmQuery.DestroyAlarmFilter(100)
End Sub
IsAlarmFilterFiltering
The IsAlarmFilterFiltering method returns true if the entire query process has been set up and is enabled to run.
Syntax
IsAlarmFilterFiltering() As Boolean
Remark
This method will return true after a successful call to StartAlarmFiltering. Once the filtering has begun, this method will only return false if the filtering has been canceled using CancelAlarmFiltering, or if the filter has been destroyed using DestroyAlarmFilter.
Example
The following example goes through the entire process of creating a filter, setting the XML filter, setting the notification point, starting the query, retrieving data, displaying the results, and cleaning up the query.
Sub
'-----------------SETUP------------------
Dim date1, date2
date1 = Date - 10
date2 = Date
Dim startDate, endDate
startDate = CDate(date1)
endDate = CDate(date2)
'create alarm filter for alarms between now and 10 days ago
Dim bCreatedOk
bCreatedOk = AlarmQuery.CreateAlarmFilter(startDate, endDate, 5)
'initialize the filter (this step is good practice)
AlarmQuery.ClearQueryResults
'set the service-specific filter from an existing XML (see the documentation for
'SetAlarmFilterAsXml for an example of an XML filter)
Dim bSetFilter
bSetFilter = AlarmQuery.SetAlarmFilterAsXml(g_xmlFilter, false)
AlarmQuery.SetAlarmSiteServices("CYGDEMO.CAS")
'set notification point
AlarmQuery.SetNotificationPoint "CYGDEMO.UIS:EVENTIF_NOTIFICATION_PT"
'-----------------EXECUTION------------------
AlarmQuery.StartAlarmFiltering()
'check to see if filter has been set up correctly
Dim bIsFiltering, bIsRunning
bIsFiltering = AlarmQuery.IsAlarmFilterFiltering()
bIsRunning = AlarmQuery.IsAlarmFilterRunning()
WScript.Sleep(1000)
Dim pvTagList, bAlarmsRetrieved
pvTagList = ""
bAlarmsRetrieved = AlarmQuery.GetFilteredAlarmList(pvTagList)
Dim nSize, bSizeRetrieved
nSize = 0
bSizeRetrieved = AlarmQuery.GetFilteredAlarmListSize(nSize)
If nSize > 0 Then
Dim strTag, pvAlarmInfoXml, bAlarmRetrieved, iRec
For iRec = 0 To UBound(pvTagList)
strTag = pvTagList(iRec)
pvAlarmInfoXml = ""
bAlarmRetrieved = AlarmQuery.GetAlarmInfoAsXml(strTag, pvAlarmInfoXml)
MsgBox pvAlarmInfoXml
Next
'clear the query and the cache
AlarmQuery.ClearQueryResults
End If
'alarm query is finished
AlarmQuery.CancelAlarmFiltering()
AlarmQuery.DestroyAlarmFilter(100)
End Sub
IsAlarmFilterRunning
The IsAlarmFilterRunning method returns true if the alarm query thread is running.
Syntax
IsAlarmFilterRunning() As Boolean
Remark
The alarm query thread is executed after an alarm filter is created; therefore, after an alarm filter is created, this method will only return false if the filter has been destroyed using DestroyAlarmFilter.
Example
The following example creates an alarm filter, checks that it is running, destroys it, and checks that it is no longer running.
Sub
Dim bCreatedOk
bCreatedOk = AlarmQuery.CreateAlarmFilter("10/1/2023", "10/4/2023", 5)
Dim bRunning
bRunning = AlarmQuery.IsAlarmFilterRunning()
MsgBox bRunning 'should be "True"
AlarmQuery.DestroyAlarmFilter(100)
bRunning = AlarmQuery.IsAlarmFilterRunning()
MsgBox bRunning 'should be "False"
End Sub
SetAlarmFilterAsXml
The SetAlarmFilterAsXml method sets the alarm filter from an XML string.
Syntax
SetAlarmFilterAsXml(XmlFilter As String, FilterContainsDates As Boolean) As Boolean
Parameters
| Parameter | Required | Description |
|---|---|---|
|
XmlFilter |
Yes |
The XML string representing the alarm filter to be set. |
|
FilterContainsDates |
Yes |
Specify "true" if the XmlFilter parameter contains a rule for the "ReportTime" property. If this parameter is set to "false", the filter will use the dates specified in the parameters of CreateAlarmFilter. |
Remark
This method returns false if the XML filter is invalid.
Example
The following is an example of an XML alarm filter.
<ExportedRules ruleDataIdentifier='CAS Alarm Rules'>
<Rules enabled='true' inverted='false' op='1' name=''>
<Rule enabled='true' name='' referenceAttr='0' compareToType='0' externalData='' value='9/1/2023' operator='>=' qualifer='Case Insensitive'>
<compareItem property='ReportTime' type='0' />
</Rule>
<Rule enabled='true' name='' referenceAttr='0' compareToType='0' externalData='' value='10/1/2023' operator='<=' qualifer='Case Insensitive'>
<compareItem property='ReportTime' type='0' />
</Rule>
<Rule enabled='true' name='' referenceAttr='0' compareToType='0' externalData='' value='HIGH_ALARM' operator='=' qualifer='Case Insensitive'>
<compareItem property='AlarmCond' type='0' />
</Rule>
</Rules>
</ExportedRules>
Note:
The XML for the filter rule uses the spelling "qualifer=" rather than "qualifier=". See Adding Filter Rule Definitions for an explanation of this discrepancy.
This filter will select all alarms for which (ReportTime >= "9/1/2023" AND ReportTime <= "10/1/2023" AND AlarmCond = "HIGH_ALARM"). Note that the "op='1'" attribute specifies that the rules are ANDed. To OR a set of rules, use "op='0'". For a complete list of CAS XML property names, see CAS XML Properties.
A blank filter may be provided as long as FilterContainsDates parameter is set to false, start and end dates are provided with CreateAlarmFilter, and a site service list is provided with SetAlarmSiteServices.
Example
The following example goes through the entire process of creating a filter, setting the XML filter, setting the notification point, starting the query, retrieving data, displaying the results, and cleaning up the query.
Sub
'-----------------SETUP------------------
Dim date1, date2
date1 = Date - 10
date2 = Date
Dim startDate, endDate
startDate = CDate(date1)
endDate = CDate(date2)
'create alarm filter for alarms between now and 10 days ago
Dim bCreatedOk
bCreatedOk = AlarmQuery.CreateAlarmFilter(startDate, endDate, 5)
'initialize the filter (this step is good practice)
AlarmQuery.ClearQueryResults
'set the service-specific filter from an existing XML (see the documentation for
'SetAlarmFilterAsXml for an example of an XML filter)
Dim bSetFilter
bSetFilter = AlarmQuery.SetAlarmFilterAsXml(g_xmlFilter, false)
AlarmQuery.SetAlarmSiteServices("CYGDEMO.CAS")
'set notification point
AlarmQuery.SetNotificationPoint "CYGDEMO.UIS:EVENTIF_NOTIFICATION_PT"
'-----------------EXECUTION------------------
AlarmQuery.StartAlarmFiltering()
'check to see if filter has been set up correctly
Dim bIsFiltering, bIsRunning
bIsFiltering = AlarmQuery.IsAlarmFilterFiltering()
bIsRunning = AlarmQuery.IsAlarmFilterRunning()
WScript.Sleep(1000)
Dim pvTagList, bAlarmsRetrieved
pvTagList = ""
bAlarmsRetrieved = AlarmQuery.GetFilteredAlarmList(pvTagList)
Dim nSize, bSizeRetrieved
nSize = 0
bSizeRetrieved = AlarmQuery.GetFilteredAlarmListSize(nSize)
If nSize > 0 Then
Dim strTag, pvAlarmInfoXml, bAlarmRetrieved, iRec
For iRec = 0 To UBound(pvTagList)
strTag = pvTagList(iRec)
pvAlarmInfoXml = ""
bAlarmRetrieved = AlarmQuery.GetAlarmInfoAsXml(strTag, pvAlarmInfoXml)
MsgBox pvAlarmInfoXml
Next
'clear the query and the cache
AlarmQuery.ClearQueryResults
End If
'alarm query is finished
AlarmQuery.CancelAlarmFiltering()
AlarmQuery.DestroyAlarmFilter(100)
End Sub
SetAlarmSiteServices
The SetAlarmSiteServices method defines the list of CAS site services for the alarm filter.
Syntax
SetAlarmSiteServices(SiteServices As String) As Boolean
Parameters
| Parameter | Required | Description |
|---|---|---|
|
SiteServices |
Yes |
A semicolon-delimited list of CAS Site.Services (for example, "CYGDEMO.CAS;CYGDEMO.CAS1"). |
Remark
This method will only return false if a filter has not yet been created.
Example
The following example goes through the entire process of creating a filter, setting the XML filter, setting the notification point, starting the query, retrieving data, displaying the results, and cleaning up the query.
Sub
'-----------------SETUP------------------
Dim date1, date2
date1 = Date - 10
date2 = Date
Dim startDate, endDate
startDate = CDate(date1)
endDate = CDate(date2)
'create alarm filter for alarms between now and 10 days ago
Dim bCreatedOk
bCreatedOk = AlarmQuery.CreateAlarmFilter(startDate, endDate, 5)
'initialize the filter (this step is good practice)
AlarmQuery.ClearQueryResults
'set the service-specific filter from an existing XML (see the documentation for
'SetAlarmFilterAsXml for an example of an XML filter)
Dim bSetFilter
bSetFilter = AlarmQuery.SetAlarmFilterAsXml(g_xmlFilter, false)
AlarmQuery.SetAlarmSiteServices("CYGDEMO.CAS")
'set notification point
AlarmQuery.SetNotificationPoint "CYGDEMO.UIS:EVENTIF_NOTIFICATION_PT"
'-----------------EXECUTION------------------
AlarmQuery.StartAlarmFiltering()
'check to see if filter has been set up correctly
Dim bIsFiltering, bIsRunning
bIsFiltering = AlarmQuery.IsAlarmFilterFiltering()
bIsRunning = AlarmQuery.IsAlarmFilterRunning()
WScript.Sleep(1000)
Dim pvTagList, bAlarmsRetrieved
pvTagList = ""
bAlarmsRetrieved = AlarmQuery.GetFilteredAlarmList(pvTagList)
Dim nSize, bSizeRetrieved
nSize = 0
bSizeRetrieved = AlarmQuery.GetFilteredAlarmListSize(nSize)
If nSize > 0 Then
Dim strTag, pvAlarmInfoXml, bAlarmRetrieved, iRec
For iRec = 0 To UBound(pvTagList)
strTag = pvTagList(iRec)
pvAlarmInfoXml = ""
bAlarmRetrieved = AlarmQuery.GetAlarmInfoAsXml(strTag, pvAlarmInfoXml)
MsgBox pvAlarmInfoXml
Next
'clear the query and the cache
AlarmQuery.ClearQueryResults
End If
'alarm query is finished
AlarmQuery.CancelAlarmFiltering()
AlarmQuery.DestroyAlarmFilter(100)
End Sub
SetNotificationPoint
The SetNotificationPoint method sets the CVS point which will contain a notification of when the queries have completed.
Syntax
SetNotificationPoint(Tag As String) As Boolean
Parameters
| Parameter | Required | Description |
|---|---|---|
|
Tag |
Yes |
The CVS tag of the point to be used for notifications (for example, "CYGDEMO.UIS:EVENTIF_NOTIFICATION_PT"). |
Remark
This method will return false if the specified tag is invalid. Note that this method does not actually create a CVS point. A CVS point with the specified tag must exist prior to starting alarm filtering in order for CVS notifications to succeed.
Example
The following example goes through the entire process of creating a filter, setting the XML filter, setting the notification point, starting the query, retrieving data, displaying the results, and cleaning up the query.
Sub
'-----------------SETUP------------------
Dim date1, date2
date1 = Date - 10
date2 = Date
Dim startDate, endDate
startDate = CDate(date1)
endDate = CDate(date2)
'create alarm filter for alarms between now and 10 days ago
Dim bCreatedOk
bCreatedOk = AlarmQuery.CreateAlarmFilter(startDate, endDate, 5)
'initialize the filter (this step is good practice)
AlarmQuery.ClearQueryResults
'set the service-specific filter from an existing XML (see the documentation for
'SetAlarmFilterAsXml for an example of an XML filter)
Dim bSetFilter
bSetFilter = AlarmQuery.SetAlarmFilterAsXml(g_xmlFilter, false)
AlarmQuery.SetAlarmSiteServices("CYGDEMO.CAS")
'set notification point
AlarmQuery.SetNotificationPoint "CYGDEMO.UIS:EVENTIF_NOTIFICATION_PT"
'-----------------EXECUTION------------------
AlarmQuery.StartAlarmFiltering()
'check to see if filter has been set up correctly
Dim bIsFiltering, bIsRunning
bIsFiltering = AlarmQuery.IsAlarmFilterFiltering()
bIsRunning = AlarmQuery.IsAlarmFilterRunning()
WScript.Sleep(1000)
Dim pvTagList, bAlarmsRetrieved
pvTagList = ""
bAlarmsRetrieved = AlarmQuery.GetFilteredAlarmList(pvTagList)
Dim nSize, bSizeRetrieved
nSize = 0
bSizeRetrieved = AlarmQuery.GetFilteredAlarmListSize(nSize)
If nSize > 0 Then
Dim strTag, pvAlarmInfoXml, bAlarmRetrieved, iRec
For iRec = 0 To UBound(pvTagList)
strTag = pvTagList(iRec)
pvAlarmInfoXml = ""
bAlarmRetrieved = AlarmQuery.GetAlarmInfoAsXml(strTag, pvAlarmInfoXml)
MsgBox pvAlarmInfoXml
Next
'clear the query and the cache
AlarmQuery.ClearQueryResults
End If
'alarm query is finished
AlarmQuery.CancelAlarmFiltering()
AlarmQuery.DestroyAlarmFilter(100)
End Sub
StartAlarmFiltering
The StartAlarmFiltering method initiates alarm filtering on the background thread.
Syntax
StartAlarmFiltering() As Boolean
Remark
This method returns false if no alarm filter has been created.
It is good practice to clear any previous query results with ClearQueryResults before calling this method.
Example
The following example goes through the entire process of creating a filter, setting the XML filter, setting the notification point, starting the query, retrieving data, displaying the results, and cleaning up the query.
Sub
'-----------------SETUP------------------
Dim date1, date2
date1 = Date - 10
date2 = Date
Dim startDate, endDate
startDate = CDate(date1)
endDate = CDate(date2)
'create alarm filter for alarms between now and 10 days ago
Dim bCreatedOk
bCreatedOk = AlarmQuery.CreateAlarmFilter(startDate, endDate, 5)
'initialize the filter (this step is good practice)
AlarmQuery.ClearQueryResults
'set the service-specific filter from an existing XML (see the documentation for
'SetAlarmFilterAsXml for an example of an XML filter)
Dim bSetFilter
bSetFilter = AlarmQuery.SetAlarmFilterAsXml(g_xmlFilter, false)
AlarmQuery.SetAlarmSiteServices("CYGDEMO.CAS")
'set notification point
AlarmQuery.SetNotificationPoint "CYGDEMO.UIS:EVENTIF_NOTIFICATION_PT"
'-----------------EXECUTION------------------
AlarmQuery.StartAlarmFiltering()
'check to see if filter has been set up correctly
Dim bIsFiltering, bIsRunning
bIsFiltering = AlarmQuery.IsAlarmFilterFiltering()
bIsRunning = AlarmQuery.IsAlarmFilterRunning()
WScript.Sleep(1000)
Dim pvTagList, bAlarmsRetrieved
pvTagList = ""
bAlarmsRetrieved = AlarmQuery.GetFilteredAlarmList(pvTagList)
Dim nSize, bSizeRetrieved
nSize = 0
bSizeRetrieved = AlarmQuery.GetFilteredAlarmListSize(nSize)
If nSize > 0 Then
Dim strTag, pvAlarmInfoXml, bAlarmRetrieved, iRec
For iRec = 0 To UBound(pvTagList)
strTag = pvTagList(iRec)
pvAlarmInfoXml = ""
bAlarmRetrieved = AlarmQuery.GetAlarmInfoAsXml(strTag, pvAlarmInfoXml)
MsgBox pvAlarmInfoXml
Next
'clear the query and the cache
AlarmQuery.ClearQueryResults
End If
'alarm query is finished
AlarmQuery.CancelAlarmFiltering()
AlarmQuery.DestroyAlarmFilter(100)
End Sub


